package com.sweet.thread;

// yield礼让，线程不会阻塞，会转为就绪状态和其他线程竞争cpu资源
// 礼让不一定成功
public class TestYield {
    public static void main(String[] args) {
        MyYield ty = new MyYield();
        new Thread(ty,"a").start();
        new Thread(ty, "b").start();
    }
}

class MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + ": 开始执行");
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + ": 执行结束");
    }
}
